﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComLib.ConfigService;
using System.IO.Ports;
using LogLib;
using ComLib.ComFun;
using System.IO;
using System.Reflection;

namespace YSLPages
{
    /// <summary>
    /// 手写签名配置选项
    /// </summary>
    public class SignatureOption : IniConfigBase
    {
        public SignatureOption()
            : base()
        {
        }

        public override string ConfigDirectory
        {
            get
            {
                string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                directory = directory.Substring(6);
                return directory;
            }
        }

        /// <summary>
        /// 窗口初始显示位置的X
        /// </summary>
        private int _pointX = 1366;
        public int PointX
        {
            get { return _pointX; }
            set { _pointX = value; }
        }

        /// <summary>
        /// 签名动作倒计时
        /// </summary>
        private int _countDownSecond = 300;
        public int CountDownSecond
        {
            get { return _countDownSecond; }
            set { _countDownSecond = value; }
        }

        private int _signType = 0;
        public int SignType
        {
            get { return _signType; }
            set { _signType = value; }
        }

        public override bool Save()
        {
            base.Save();
            SaveField("PointX", _pointX);
            SaveField("CountDownSecond", _countDownSecond);
            SaveField("SignType", _signType);
            return true;
        }

        public override bool Load()
        {
            base.Load();
            try
            {
                _pointX = LoadInt32Value("PointX");
                _countDownSecond = LoadInt32Value("CountDownSecond");
                _signType = LoadInt32Value("SignType");
            }
            catch (Exception ex)
            {
                ErrorMessage = string.Format("配置文件{0}加载错误:\n\t{1}", ConfigFilePath, ex.Message);
                Log.WriteException(ex.ToString());
                return false;
            }
            return true;
        }

        public override string ToString()
        {          
            StringBuilder builder = new StringBuilder("签名页面选项配置: ");
            FillFieldValueStringDelegate FillString =
                (string field, object val) =>
                {
                    builder.Append("[");
                    builder.Append(field);
                    builder.Append("]: ");
                    builder.Append(val.ToString() + "; ");
                };
            FillString("窗口位置X", _pointX);
            FillString("倒计时", _countDownSecond);
            FillString("SignType", _signType);
            return builder.ToString();
        }
    }
}
